home *** CD-ROM | disk | FTP | other *** search
/ Champak 64 / Volume 64 - JOGO DISK .iso / Games / the_best_every_day.swf / scripts / __Packages / Patrick.as < prev    next >
Text File  |  2008-04-10  |  17KB  |  583 lines

  1. class Patrick extends sarbakan.visual.element.DynamicElement
  2. {
  3.    static var NUMBER_SPEED_X = 3;
  4.    static var NUMBER_SPEED_Y = 2;
  5.    static var NUMBER_PATRICK_MEMORY = 30;
  6.    static var NUMBER_SCREEN_WIDTH = 600;
  7.    static var NUMBER_SCREEN_HEIGHT = 300;
  8.    static var NUMBER_HUD_ADJUST = 65;
  9.    static var NUMBER_EASTEREGG = 46;
  10.    var DEFAULT_STATE = "Start";
  11.    var nTimeViewPoint = 50;
  12.    function Patrick(l_mcPatrick, l_oLevel, l_nMaxStrength)
  13.    {
  14.       super(l_mcPatrick._name);
  15.       this.setMC(l_mcPatrick);
  16.       this.keyListener = new Object();
  17.       this.enable();
  18.       this.oLevel = l_oLevel;
  19.       this.oConfusionTime = undefined;
  20.       this.nMaxStrength = l_nMaxStrength;
  21.       this.nStrength = this.nMaxStrength;
  22.       this.nStrengthDivider = this.nMaxStrength / 60;
  23.       this.bActive = false;
  24.       this.bTrapped = false;
  25.       this.bLadder = false;
  26.       this.nTimeSpend = 0;
  27.       this.mcArrow = this.mc._parent._parent.Arrow_mc;
  28.    }
  29.    function setAction(l_sAction)
  30.    {
  31.       if(this.bActive && !this.bTrapped)
  32.       {
  33.          this.l_sAction();
  34.       }
  35.       if(this.mc._parent._parent.mcSpongebob._currentframe != Patrick.NUMBER_EASTEREGG)
  36.       {
  37.          this.mc._parent._parent.mcSpongebob.gotoAndStop(l_sAction);
  38.          if(this.mc._parent._parent.mcSpongebob.state._currentframe == this.mc._parent._parent.mcSpongebob.state._totalframes)
  39.          {
  40.             this.mc._parent._parent.mcSpongebob.state.gotoAndPlay(1);
  41.          }
  42.       }
  43.    }
  44.    function update()
  45.    {
  46.       super.update();
  47.       if(this.bActive)
  48.       {
  49.          if(this.sState == "Move")
  50.          {
  51.             this.StrengthManagement();
  52.          }
  53.          this.FearEdge();
  54.          this.CheckConfusion();
  55.          if(this.fLoopFunction)
  56.          {
  57.             this.fLoopFunction();
  58.          }
  59.          if(this.oTime)
  60.          {
  61.             this.oTime.update();
  62.             if(this.oTime.__get__timeOut())
  63.             {
  64.                this.fLoopFunction = undefined;
  65.             }
  66.          }
  67.          this.placeArrow();
  68.       }
  69.       else if(this.mcArrow._currentframe != 1)
  70.       {
  71.          this.mcArrow.gotoAndStop(1);
  72.       }
  73.    }
  74.    function setControls(l_mcControls)
  75.    {
  76.       this.keyListener.onKeyDown = function()
  77.       {
  78.          if(!_global.C.oGame.bMiniGame && !_global.Pack.bPaused)
  79.          {
  80.             if(Key.isDown(38))
  81.             {
  82.                _global.C.oGame.oLevel.oPatrick.setAction("MoveUp");
  83.             }
  84.             else if(Key.isDown(37))
  85.             {
  86.                _global.C.oGame.oLevel.oPatrick.setAction("MoveLeft");
  87.             }
  88.             else if(Key.isDown(39))
  89.             {
  90.                _global.C.oGame.oLevel.oPatrick.setAction("MoveRight");
  91.             }
  92.             else if(Key.isDown(40))
  93.             {
  94.                _global.C.oGame.oLevel.oPatrick.setAction("MoveDown");
  95.             }
  96.             else if(Key.isDown(32))
  97.             {
  98.                _global.C.oGame.oLevel.oPatrick.setAction("DropBoxHere");
  99.             }
  100.             else if(Key.isDown(77))
  101.             {
  102.                _global.C.oGame.oLevel.oPatrick.setAction("CheerUp");
  103.             }
  104.             else if(Key.getCode() == 187 || Key.getCode() == 107)
  105.             {
  106.                _global.C.oGame.oLevel.oPatrick.setAction("EasterEgg");
  107.             }
  108.          }
  109.       };
  110.       Key.addListener(this.keyListener);
  111.    }
  112.    function ClearControls()
  113.    {
  114.       Key.removeListener(this.keyListener);
  115.    }
  116.    function trap(l_bTrapped, l_mcObstacle)
  117.    {
  118.       this.bTrapped = l_bTrapped;
  119.       if(_global.C.oGame.bGamePlaying)
  120.       {
  121.          if(this.bTrapped)
  122.          {
  123.             switch(l_mcObstacle.getType())
  124.             {
  125.                case "Bubbles":
  126.                   this.mc.gotoAndStop("Idle");
  127.                   this.mc.state.Bras.gotoAndStop(2);
  128.                   this.nSpeedX = 0;
  129.                   this.nSpeedY = 0;
  130.                   this.fLoopFunction = undefined;
  131.                   break;
  132.                case "Banana":
  133.                case "Slobber":
  134.                   this.setState("BoxLost");
  135.                   this.nSpeedX = 0;
  136.                   this.nSpeedY = 0;
  137.                   this.fLoopFunction = undefined;
  138.                   l_mcObstacle.fRemove();
  139.                   _global.C.dropBox(false);
  140.                   this.nStrength = this.nMaxStrength;
  141.                   break;
  142.                case "Gary":
  143.                   this.bTrapped = false;
  144.             }
  145.          }
  146.       }
  147.    }
  148.    function win()
  149.    {
  150.       this.Idle();
  151.       this.setState("Winner");
  152.       this.mc.gotoAndStop("Winner");
  153.       super.update();
  154.       this.bActive = false;
  155.    }
  156.    function Winner()
  157.    {
  158.       if(this.mc.state._currentframe == this.mc.state._totalframes)
  159.       {
  160.          this.setState("Idle");
  161.          _global.C.oGame.EndGame(true);
  162.       }
  163.    }
  164.    function getCamCoord()
  165.    {
  166.       return {x:this.mc._x - Patrick.NUMBER_HUD_ADJUST - Patrick.NUMBER_SCREEN_WIDTH / 2,y:this.mc._y - Patrick.NUMBER_SCREEN_HEIGHT / 2};
  167.    }
  168.    function StrengthManagement()
  169.    {
  170.       if(this.nStrength > 0)
  171.       {
  172.          this.nStrength = this.nStrength - 1;
  173.          this.mc.state.mc_Arm.gotoAndStop(Math.ceil((this.nMaxStrength - this.nStrength) / this.nStrengthDivider));
  174.          this.mc.state.Bras.BrasAnim.gotoAndStop(Math.ceil((this.nMaxStrength - this.nStrength) / this.nStrengthDivider));
  175.          if(this.nStrength == 0)
  176.          {
  177.             this.Idle();
  178.             this.nStrength = this.nMaxStrength;
  179.             this.setState("DropBox");
  180.             this.mc.gotoAndStop("DropBox");
  181.             this.bActive = false;
  182.             if(!this.collideWithMap("floor",this.mc.mcEdgeDetector))
  183.             {
  184.                this.mc._xscale *= -1;
  185.             }
  186.             _global.C.dropBox(false);
  187.             this.fLoopFunction = undefined;
  188.          }
  189.       }
  190.    }
  191.    function Ballance()
  192.    {
  193.       this.bActive = false;
  194.       this.nSpeedX = 0;
  195.       this.nSpeedY = 0;
  196.       if(this.mc.state._currentframe == this.mc.state._totalframes)
  197.       {
  198.          this.setState("ViewPoint");
  199.          this.mc.gotoAndStop("ViewPoint");
  200.          this.oLevel.setNewDropPoint();
  201.          this.mc._xscale *= -1;
  202.       }
  203.    }
  204.    function FearEdge()
  205.    {
  206.       if(!this.collideWithMap("floor",this.mc.mcEdgeDetector) && this.nSpeedX != 0 && this.mc._y < 300)
  207.       {
  208.          this.setState("Ballance");
  209.          this.mc.gotoAndStop("Winner");
  210.          this.nStrength = this.nMaxStrength;
  211.          this.bActive = false;
  212.          _global.C.dropBox(false);
  213.          this.fLoopFunction = undefined;
  214.       }
  215.       else if(!this.collideWithMap("floor",this.mc.mcEdgeDetector) && this.nSpeedX != 0 && this.mc._y > 300)
  216.       {
  217.          this.nSpeedX *= -1;
  218.       }
  219.    }
  220.    function CheckConfusion()
  221.    {
  222.       if(this.oConfusionTime != undefined)
  223.       {
  224.          this.oConfusionTime.update();
  225.          if(this.oConfusionTime.__get__timeOut())
  226.          {
  227.             this.oConfusionTime = undefined;
  228.          }
  229.       }
  230.    }
  231.    function Idle()
  232.    {
  233.       this.nSpeedX = 0;
  234.       this.nSpeedY = 0;
  235.    }
  236.    function DropBox()
  237.    {
  238.       this.bActive = false;
  239.       this.nSpeedX = 0;
  240.       this.nSpeedY = 0;
  241.       if(this.mc.state._currentframe == this.mc.state._totalframes)
  242.       {
  243.          this.setState("ViewPoint");
  244.          this.mc.gotoAndStop("ViewPoint");
  245.          this.oLevel.setNewDropPoint();
  246.       }
  247.    }
  248.    function BoxLost()
  249.    {
  250.       this.bActive = false;
  251.       this.nSpeedX = 0;
  252.       this.nSpeedY = 0;
  253.       if(this.mc.state._currentframe == this.mc.state._totalframes)
  254.       {
  255.          this.setState("ViewPoint");
  256.          this.mc.gotoAndStop("ViewPoint");
  257.          this.oLevel.setNewDropPoint();
  258.       }
  259.    }
  260.    function BoxDown()
  261.    {
  262.       this.nSpeedX = 0;
  263.       this.nSpeedY = 0;
  264.       this.bActive = false;
  265.       if(this.mc.state._currentframe == this.mc.state._totalframes)
  266.       {
  267.          this.setState("ViewPoint");
  268.          this.mc.gotoAndStop("ViewPoint");
  269.          this.oLevel.setNewDropPoint();
  270.       }
  271.    }
  272.    function BoxReceive()
  273.    {
  274.       if(this.mc.state._currentframe == this.mc.state._totalframes)
  275.       {
  276.          this.bActive = true;
  277.          this.nSpeedY = 0;
  278.          this.setState("Move");
  279.          if(this.mc._xscale == 100)
  280.          {
  281.             this.nSpeedX = Patrick.NUMBER_SPEED_X;
  282.          }
  283.          else
  284.          {
  285.             this.nSpeedX = - Patrick.NUMBER_SPEED_X;
  286.          }
  287.       }
  288.    }
  289.    function ViewPoint()
  290.    {
  291.       this.bActive = false;
  292.       this.oConfusionTime = undefined;
  293.       this.nStrength = this.nMaxStrength;
  294.       this.bTrapped = false;
  295.       this.setState("Idle");
  296.       if(_global.Pack.nFunds >= 0)
  297.       {
  298.          this.oLevel.oCam.travelTo(this.mc._parent[this.sDropPoint]._x - Patrick.NUMBER_HUD_ADJUST - Patrick.NUMBER_SCREEN_WIDTH / 2,this.mc._parent[this.sDropPoint]._y - Patrick.NUMBER_SCREEN_HEIGHT / 2,this.CamReturn);
  299.       }
  300.    }
  301.    function Start()
  302.    {
  303.       this.mc.gotoAndStop("Idle");
  304.       this.nTimeSpend = this.nTimeSpend + 1;
  305.       if(this.nTimeSpend > 50)
  306.       {
  307.          this.nTimeSpend = 0;
  308.          this.setState("ViewPoint");
  309.          this.mc.gotoAndStop("ViewPoint");
  310.       }
  311.    }
  312.    function CamReturn()
  313.    {
  314.       _global.C.oGame.oLevel.oPatrick.setState("BoxReceive");
  315.       _global.C.oGame.oLevel.oPatrick.mc.gotoAndStop("BoxReceive");
  316.       _global.C.oGame.oLevel.oCam.travelTo(_global.C.oGame.oLevel.oPatrick.mc._x - Patrick.NUMBER_HUD_ADJUST - Patrick.NUMBER_SCREEN_WIDTH / 2,_global.C.oGame.oLevel.oPatrick.mc._y - Patrick.NUMBER_SCREEN_HEIGHT / 2);
  317.    }
  318.    function MoveLeft()
  319.    {
  320.       if(this.oConfusionTime && !this.bLadder)
  321.       {
  322.          if(this.sLastArrow != "Left")
  323.          {
  324.             this.nStrength = 1;
  325.             this.StrengthManagement();
  326.          }
  327.       }
  328.       else if(!this.bLadder)
  329.       {
  330.          this.sLastArrow = "Left";
  331.          this.oConfusionTime = new sarbakan.utils.Time(0,0);
  332.          this.oConfusionTime.__set__frames(10);
  333.          this.nSpeedX = - Patrick.NUMBER_SPEED_X;
  334.          this.nSpeedY = 0;
  335.          this.setState("Move");
  336.       }
  337.       else
  338.       {
  339.          this.sTimedNextAction = "MoveLeft";
  340.       }
  341.    }
  342.    function MoveRight()
  343.    {
  344.       if(this.oConfusionTime && !this.bLadder)
  345.       {
  346.          if(this.sLastArrow != "Right")
  347.          {
  348.             this.nStrength = 1;
  349.             this.StrengthManagement();
  350.          }
  351.       }
  352.       else if(!this.bLadder)
  353.       {
  354.          this.sLastArrow = "Right";
  355.          this.oConfusionTime = new sarbakan.utils.Time(0,0);
  356.          this.oConfusionTime.__set__frames(10);
  357.          this.nSpeedX = Patrick.NUMBER_SPEED_X;
  358.          this.nSpeedY = 0;
  359.          this.setState("Move");
  360.       }
  361.       else
  362.       {
  363.          this.sTimedNextAction = "MoveRight";
  364.       }
  365.    }
  366.    function CheerUp()
  367.    {
  368.       this.nStrength += 150;
  369.       this.nStrength = Math.min(this.nStrength,this.nMaxStrength);
  370.    }
  371.    function MoveDown()
  372.    {
  373.       if(this.sState == "Move")
  374.       {
  375.          if(this.LadderCollide(-15))
  376.          {
  377.             this.nSpeedX = 0;
  378.             this.nTimeSpend = 0;
  379.             this.nSpeedY = Patrick.NUMBER_SPEED_Y;
  380.             this.setState("DownLadder");
  381.             this.fLoopFunction = this.loopLadderDown;
  382.             this.bLadder = true;
  383.             this.oTime = undefined;
  384.          }
  385.          else
  386.          {
  387.             this.oTime = new sarbakan.utils.Time(0,1);
  388.             this.oTime.__set__frames(12);
  389.             this.fLoopFunction = this.loopFindLadderDown;
  390.          }
  391.       }
  392.    }
  393.    function loopLadderDown()
  394.    {
  395.       this.nTimeSpend = this.nTimeSpend + 1;
  396.       if(this.nTimeSpend >= 10)
  397.       {
  398.          if(!this.LadderCollide(5))
  399.          {
  400.             if(!this.sTimedNextAction)
  401.             {
  402.                this.setRandomDirection();
  403.             }
  404.             else
  405.             {
  406.                this.setAction(this.sTimedNextAction);
  407.             }
  408.             this.mc._y -= Patrick.NUMBER_SPEED_Y;
  409.             this.fLoopFunction = undefined;
  410.             this.bLadder = false;
  411.          }
  412.       }
  413.    }
  414.    function loopFindLadderDown()
  415.    {
  416.       if(this.LadderCollide(-15))
  417.       {
  418.          this.oTime = undefined;
  419.          this.nSpeedX = 0;
  420.          this.nTimeSpend = 0;
  421.          this.nSpeedY = Patrick.NUMBER_SPEED_Y;
  422.          this.setState("DownLadder");
  423.          this.fLoopFunction = this.loopLadderDown;
  424.          this.bLadder = true;
  425.       }
  426.    }
  427.    function MoveUp()
  428.    {
  429.       if(this.sState == "Move")
  430.       {
  431.          if(this.LadderCollide(15))
  432.          {
  433.             this.nSpeedX = 0;
  434.             this.nTimeSpend = 0;
  435.             this.nSpeedY = - Patrick.NUMBER_SPEED_Y;
  436.             this.setState("UpLadder");
  437.             this.fLoopFunction = this.loopLadderUp;
  438.             this.bLadder = true;
  439.             this.oTime = undefined;
  440.          }
  441.          else
  442.          {
  443.             this.oTime = new sarbakan.utils.Time(0,1);
  444.             this.oTime.__set__frames(12);
  445.             this.fLoopFunction = this.loopFindLadderUp;
  446.          }
  447.       }
  448.    }
  449.    function loopLadderUp()
  450.    {
  451.       this.nTimeSpend = this.nTimeSpend + 1;
  452.       if(this.nTimeSpend >= 10)
  453.       {
  454.          if(!this.LadderCollide(-5))
  455.          {
  456.             if(!this.sTimedNextAction)
  457.             {
  458.                this.setRandomDirection();
  459.             }
  460.             else
  461.             {
  462.                this.setAction(this.sTimedNextAction);
  463.             }
  464.             this.mc._y += Patrick.NUMBER_SPEED_Y;
  465.             this.fLoopFunction = undefined;
  466.             this.bLadder = false;
  467.          }
  468.       }
  469.    }
  470.    function loopFindLadderUp()
  471.    {
  472.       if(this.LadderCollide(15))
  473.       {
  474.          this.oTime = undefined;
  475.          this.nSpeedX = 0;
  476.          this.nTimeSpend = 0;
  477.          this.nSpeedY = - Patrick.NUMBER_SPEED_Y;
  478.          this.setState("UpLadder");
  479.          this.fLoopFunction = this.loopLadderUp;
  480.          this.bLadder = true;
  481.       }
  482.    }
  483.    function LadderCollide(_modifier)
  484.    {
  485.       var _loc4_ = false;
  486.       var _loc3_ = this.mc.mcDetector.getBounds(_global.GS);
  487.       var _loc6_ = (_loc3_.xMax + _loc3_.xMin) / 2;
  488.       var _loc5_ = _loc3_.yMax - _modifier;
  489.       if(this.mc._parent.Ladders.hitTest(_loc6_,_loc5_,true))
  490.       {
  491.          _loc4_ = true;
  492.       }
  493.       else
  494.       {
  495.          this.bLadder = false;
  496.       }
  497.       return _loc4_;
  498.    }
  499.    function DropPointCollide()
  500.    {
  501.       var _loc2_ = false;
  502.       if(this.mc.hitTest(this.mc._parent[this.sDropPoint]) && this.getElement(this.sDropPoint).mc._currentframe == 1)
  503.       {
  504.          _loc2_ = true;
  505.       }
  506.       return _loc2_;
  507.    }
  508.    function DropBoxHere()
  509.    {
  510.       if(!this.bLadder && this.DropPointCollide())
  511.       {
  512.          this.setState("BoxDown");
  513.          this.mc.gotoAndStop("BoxDown");
  514.          _global.C.dropBox(true);
  515.       }
  516.       else if(!this.bLadder)
  517.       {
  518.          this.setState("BoxDown");
  519.          this.mc.gotoAndStop("BoxDown");
  520.          _global.C.dropBox(false);
  521.       }
  522.    }
  523.    function setRandomDirection()
  524.    {
  525.       this.nSpeedY = 0;
  526.       this.setState("Move");
  527.       var _loc2_ = Math.ceil(Math.random() * 2);
  528.       if(_loc2_ == 1)
  529.       {
  530.          this.nSpeedX = - Patrick.NUMBER_SPEED_X;
  531.       }
  532.       else
  533.       {
  534.          this.nSpeedX = Patrick.NUMBER_SPEED_X;
  535.       }
  536.    }
  537.    function set dropPoint(l_sDropPoint)
  538.    {
  539.       this.sDropPoint = l_sDropPoint;
  540.    }
  541.    function placeArrow()
  542.    {
  543.       var _loc3_ = false;
  544.       var _loc2_ = "";
  545.       if(Math.abs(this.mc._y - this.mc._parent[this.sDropPoint]._y) > 100)
  546.       {
  547.          _loc3_ = true;
  548.          if(this.mc._y - this.mc._parent[this.sDropPoint]._y > 0)
  549.          {
  550.             _loc2_ += "U";
  551.          }
  552.          else
  553.          {
  554.             _loc2_ += "D";
  555.          }
  556.       }
  557.       if(Math.abs(this.mc._x - this.mc._parent[this.sDropPoint]._x) > 250)
  558.       {
  559.          _loc3_ = true;
  560.          if(this.mc._x - this.mc._parent[this.sDropPoint]._x > 0)
  561.          {
  562.             _loc2_ += "L";
  563.          }
  564.          else
  565.          {
  566.             _loc2_ += "R";
  567.          }
  568.       }
  569.       else if(Math.abs(this.mc._y - this.mc._parent[this.sDropPoint]._y) < 150)
  570.       {
  571.          _loc3_ = false;
  572.       }
  573.       if(_loc3_)
  574.       {
  575.          this.mcArrow.gotoAndStop(_loc2_);
  576.       }
  577.       else
  578.       {
  579.          this.mcArrow.gotoAndStop(1);
  580.       }
  581.    }
  582. }
  583.